package com.capgemini.business.mapper;

import com.capgemini.business.entity.Project;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProjectMapper {
    // Retrieve查询接口
    @Select("select * from project")
    List<Project> findAll();  // 返回列表

    // Create新增接口
    @Insert("insert into project (id, name, description, startTime, endTime, budget, master, members) " +
            "values (#{id}, #{name}, #{description}, #{startTime}, #{endTime}, #{budget}, #{master}, #{members})")
    @Options(useGeneratedKeys = true, keyProperty = "id")  // 用于指定MyBatis在插入记录后自动生成并返回主键id。
    void insertProject(Project project);

    // Update修改接口
    @Update("update project set name=#{name}, description=#{description}, startTime=#{startTime}, endTime=#{endTime}, budget=#{budget}, master=#{master}, members=#{members} where id=#{id}")
    void updateProject(Project project);

    // Delete删除接口
    @Delete("delete from project where id=#{id}")
    void deleteProject(int id);  // 通过id删除

    // Retrieve查询单个用户接口
    @Select("SELECT * FROM project WHERE id = #{id}")
    Project findProjectById(int id);
}
